#!/usr/bin/env python
# encoding: utf-8
"""
subprocess_helper_test.py
"""

import unittest
import logging.config

log = logging.getLogger('xmitools.tests.subprocess_helper_test')
logging.basicConfig(level=logging.INFO)

from xmitools.util.subprocess_helper import run_in_subprocess

class subprocess_helper_test(unittest.TestCase):
    def setUp(self):
        pass

    def test_run_in_subprocess_error(self):
        """test smart_wait_for_subprocess"""
        code,out,err = run_in_subprocess(['/bin/cat','/zzzz'],10)
        self.assertEqual(code,1)
        self.assertEqual(out,'')
        self.assertEqual(err,'cat: /zzzz: No such file or directory\n')

    def test_run_in_subprocess(self):
        code,out,err = run_in_subprocess(['/bin/cat','/etc/resolv.conf'],10)
        self.assertEqual(code,0)
        self.assertEqual(len(out)>0,True)
        self.assertEqual(err,'')

def suite():
    """集合测试用例"""
    suite = unittest.TestSuite()
    suite.addTest(unittest.makeSuite(subprocess_helper_test, 'test'))
    return suite

if __name__ == '__main__':
    unittest.main()